<template>
  <div class="login">
    <div class="middle-wrapper">
      <div class="title-wrapper">
        <div class="title">账号注册</div>
      </div>
      <div class="login-form">
        <el-form ref="loginForm" :model="form" :rules="rules">
			<el-form-item prop="power">
	<el-radio-group v-model="form.radio">
		<el-radio :label="1">屠宰场商家</el-radio>
		<el-radio :label="2">批发市场商家</el-radio>
		<el-radio :label="3">零售商家</el-radio>
	</el-radio-group>
			</el-form-item>
          <el-form-item prop="username">
            <el-input v-model="form.username" placeholder="请输入账号">
              <i
                slot="prefix"
                class="el-input__icon el-icon-adm-user"
                style="font-size: 18px;"
              ></i>
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              :type="passwordType"
              v-model="form.password"
              placeholder="请输入密码"
            >

            </el-input>
          </el-form-item>
        <el-form-item prop="confirmpwd">
          <el-input v-model="form.confirmpwd" placeholder="再次输入密码">
            <i
              slot="prefix"
              class="el-input__icon el-icon-adm-user"
              style="font-size: 18px;"
            ></i>
          </el-input>
        </el-form-item>
		
		<el-form-item prop="phone">
		  <el-input v-model="form.phone" placeholder="请输入手机号">
		    <i
		      slot="prefix"
		      class="el-input__icon el-icon-phone"
		      style="font-size: 18px;"
		    ></i>
		  </el-input>
		   	<el-button @click="send()" type="text">发送验证码</el-button>
		</el-form-item>
		
		<el-form-item prop="checkCode">
		  <el-input v-model="form.checkCode" placeholder="请输入验证码">
		  </el-input>
		</el-form-item>
          <el-form-item style="margin-bottom: 0;">
            <el-col :span="10" :offset="8">
              <el-form-item>
                <el-button
                  type="success" round
                  class="login-btn"
                  style="width: 100%;"
                  @click="register('loginForm')"
                >
                   注册
                </el-button>
              </el-form-item>
            </el-col>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  created() {},
  data() {
    return {
      passwordType: 'password',
      form: {
        username: '',
        password: '',
        yanzhengma: '',
		power:'',
		confirmpwd:'',
		phone:'',
		checkCode: '',
      },
      rules: {
        username: [
          { required: true, message: '账号不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ],
      }
    }
  },
  methods: {
	  send(){
	  	alert('这就发了')
	  },
	  register(){
		  if(this.form.password===this.form.confirmpwd){
		  this.axios.post('/food/user/register', response => {
		      console.log(response)
		      //登录成功后转到成功页面
		      if (response.code === 200) {
		       alert('注册成功！')
		       this.$router.push('/login')
		       }
			   else{
				   alert('该账户已被注册！注册失败')
			   }
			   })
			   }
		 else{
				alert('两次密码输入不一致！')
			}
		
	  },
	  }
	  }
</script>
<style lang="less" scoped>
.login {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-color: rgb(32, 160, 255);

  .middle-wrapper {
    position: fixed;
    width: 100%;
    margin: 0 auto;
    top: 50%;
    transform: translateY(-60%);

    .title-wrapper {
      margin-top: 50px;
      margin-bottom: 30px;
      text-align: center;
      font-size: 30px;
      font-weight: bold;
      color: #ffffff;
    }
    .login-form {
      position: relative;
      margin: 0 auto;
      width: 520px;
      padding: 30px 50px;
      box-sizing: border-box;
      border-radius: 5px;
      background-color: #ffffff;

      .el-row {
        margin-bottom: 20px;

        &:last-child {
          margin-bottom: 0;
        }

        .login-btn {
          width: 100%;
        }
      }

      .check-code-wrapper {
        display: flex;
        justify-content: space-between;
        height: 40px;

        .yanzhengma-wrapper {
          flex: 0 1 auto;
        }

        .validate-code-wrapper {
          flex: 0 0 160px;
        }
      }
    }
  }
}
</style>
